//Headers
#include "timer.h"
#include "SDL/SDL.h"

//FPS Timer
Timer::Timer()
{
    //Initialize
    startTicks = 0;
    pausedTicks = 0;
    paused = false;
    started = false;
}

void Timer::start()
{
    //Start
    started = true;

    //Unpause
    paused = false;

    //Get current clock time
    startTicks = SDL_GetTicks();
}

void Timer::stop()
{
    //Stop
    started = false;

    //Unpause
    paused = false;
}

void Timer::pause()
{
    //If running and not paused
    if(started and !paused)
    {
        //Pause
        paused = true;

        //Calc ticks
        pausedTicks = SDL_GetTicks() - startTicks;
    }
}

void Timer::unpause()
{
    //If running and paused
    if(started and paused)
    {
        //Pause
        paused = false;

        //Reset startTicks
        startTicks = SDL_GetTicks() - pausedTicks;

        //Reset paused ticks
        pausedTicks = 0;
    }
}

int Timer::get_ticks()
{
    //If started
    if(started)
    {
        //If paused
        if(paused)
        {
            return pausedTicks;
        }
        else
        {
            return SDL_GetTicks() - startTicks;
        }
    }
    //If the timer isn't running
    return 0;
}

bool Timer::is_started()
{
    return started;
}

bool Timer::is_paused()
{
    return paused;
}
